# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Bart Verhagen <bart at verhagenconsultancy dot be>

# Upstream has no tags or release versioning, see:
# https://github.com/emil-e/rapidcheck/issues/255
# Commit here was picked based on what works to build nix.
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/rapidcheck/default.nix
_commit=b78f89288c7e086d06e2a1e10b605d8375517a8a

pkgname=rapidcheck
pkgver=r1010.b78f892
pkgrel=1
pkgdesc='QuickCheck clone for C++'
arch=(loong64 x86_64 aarch64 i686 arm armv6h armv7h)
url="https://github.com/emil-e/$pkgname"
license=(BSD)
makedepends=(cmake
             git)
options=(!lto)
source=("git+$url.git#commit=$_commit")
sha256sums=('SKIP')

prepare() {
	cd "$pkgname"
	mkdir -p build
}

pkgver() {
	cd "$pkgname"
	printf "r%s.%s" \
		"$(git rev-list --count HEAD)" \
		"$(git rev-parse --short=7 HEAD)"
}

build() {
	cd "$pkgname"
	cmake \
		-G "Unix Makefiles" \
		-D CMAKE_BUILD_TYPE=Release \
		-D CMAKE_INSTALL_PREFIX="$pkgdir/usr/" \
		-D CMAKE_POSITION_INDEPENDENT_CODE=True \
		-D RC_ENABLE_EXAMPLES=Off \
		-D RC_ENABLE_TESTS=Off \
		-D RC_INSTALL_ALL_EXTRAS=On \
		-B build
	make -C build all
}

check() {
	cd "$pkgname"
	cmake \
		-G "Unix Makefiles" \
		-D CMAKE_POSITION_INDEPENDENT_CODE=True \
		-D RC_ENABLE_EXAMPLES=On \
		-B build
	make -C build counter
	build/examples/counter/counter
}

package_rapidcheck() {
	cd "$pkgname"
	cmake -P "build/cmake_install.cmake"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.md
}
